#!/bin/bash
## Platform:All Linux Based Platform
## author:Long Tao
## version:1.0
## description:This is clean image
## Company:QuDan
# 镜像仓库
IMAGE_DEPOSITORY=ccr.ccs.tencentyun.com/qudan/qudan
# username
DEPOSITORY_USERNAME=100022109603
# password
DEPOSITORY_PASSWORD=qudan@2021
IMAGE_TAG=quwan_test
app_name=quwan_test
# 获取docker 容器id和镜像id
app_stop_id=$(docker ps -a | grep "$app_name" | awk '{print $1 }')
app_delete_id=$(docker ps -a | grep "$app_name" | awk '{print $1 }')
app_image_id=$(docker images | grep "$IMAGE_TAG" | awk '{print $3 }')
echo "镜像id:" "$app_image_id"
echo "容器id:" "$app_stop_id"

# 容器正在运行,停止
if [ "$app_stop_id"x != ""x ]; then
  echo '================正在停止容器==================='
  docker stop "$app_stop_id"

fi
# 删除容器
if [ "$app_delete_id"x != ""x ]; then
  echo '================开始删除容器==================='
  docker rm "$app_delete_id"

fi
sleep 2

# 删除镜像
if [ "$app_image_id"x != ""x ]; then
  echo '================正在删除镜像==================='
  docker rmi "$app_image_id"
fi



#分配内存 堆配置推荐
#2G -Xmx1344M -Xms1344M -Xmn448M -XX:MaxMetaspaceSize=192M -XX:MetaspaceSize=192M
#3G -Xmx2048M -Xms2048M -Xmn768M -XX:MaxMetaspaceSize=256M -XX:MetaspaceSize=256M
#4G -Xmx2688M -Xms2688M -Xmn960M -XX:MaxMetaspaceSize=256M -XX:MetaspaceSize=256M
#5G -Xmx3392M -Xms3392M -Xmn1216M -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=512M
#6G -Xmx4096M -Xms4096M -Xmn1536M -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=512M
#7G -Xmx4736M -Xms4736M -Xmn1728M -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=512M
#8G -Xmx5440M -Xms5440M -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=512M